package com.study.seckill.web.api;

import com.study.exceptions.CourseSeckillOrderException;
import com.study.seckill.entity.CourseSeckillOrder;
import com.study.seckill.service.CourseSeckillOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.stereotype.Component;

import javax.swing.plaf.ColorUIResource;

/**
 * @ClassName: OrderCheckHandler
 * @Author: wYin
 * @Date: 2022/3/18 9:45
 */
@RabbitListener(queues = {"wYin-orderDead-queue"})
@Component
@Slf4j
public class OrderCheckHandler {
    @Autowired
    private CourseSeckillOrderService courseSeckillOrderService;

    @RabbitHandler
    public void receiving(CourseSeckillOrder courseSeckillOrder){
        log.info("当前的订单详情是：{}",courseSeckillOrder);
        //根据订单查询订单状态是否未支付，若是则取消订单
        String orderNumber = courseSeckillOrder.getOrderNumber();
        CourseSeckillOrder byOrderNumber = courseSeckillOrderService.findByOrderNumber(orderNumber);
//        if(byOrderNumber==null){
//            throw new CourseSeckillOrderException("没有查询到当前编号的订单信息");
//        }
        //判断订单的状态
        if(byOrderNumber.getOrderStatus().equals("n")){
            //删除订单
            boolean b = courseSeckillOrderService.removeById(byOrderNumber.getId());
        }
    }
}
